package AdminControl;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Model.HangSanXuat;
import Model.HeDieuHanh;
import Model.Mobile;
import Model.SanPham;

/**
 * Servlet implementation class UpdateProduct
 */
public class UpdateProduct extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateProduct() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
			response.setContentType("text/html;charset=UTF-8");
	        request.setCharacterEncoding("UTF-8");
	        response.setCharacterEncoding("UTF-8");
		try {
			 String mobileID = request.getParameter("mobileId");
			 int idmb=Integer.parseInt(mobileID);
			 Mobile sp= new Mobile();
		     sp.deleteMobile(idmb);

		        //Them san pham
		        String manufacturerID = request.getParameter("manufacturer");
		        String name = request.getParameter("name");
		        String price = request.getParameter("price");
		        String quantity = request.getParameter("quantity");
		        String image = request.getParameter("image");
		        String thumbnail = request.getParameter("thumbnail");
		        String date = request.getParameter("date");
		        String discount = request.getParameter("discount");
		        String discountPlace = "Áp dụng tại 21 Chùa Bộc";
		        String warranty = request.getParameter("warranty");
		        String appendix = request.getParameter("appendix");
		        String salientFeature = request.getParameter("salient_feature");
		        String waveband = request.getParameter("waveband");
		        String size = request.getParameter("size");
		        String weight = request.getParameter("weight");
		        String color = request.getParameter("color");
		        String resolution = request.getParameter("resolution");
		        String screenInfo = request.getParameter("screen_info");
		        String language = request.getParameter("language");
		        String shake = request.getParameter("shake");
		        String ringTone = request.getParameter("ring_tone");
		        String speaker = request.getParameter("speaker");
		        String internalMemory = request.getParameter("internal_memory");
		        String externalMemory = request.getParameter("external_memory");
		        String gprs = request.getParameter("gprs");
		        String edge = request.getParameter("edge");
		        String _3g = request.getParameter("3g");
		        String wlan = request.getParameter("wlan");
		        String bluetooth = request.getParameter("bluetooth");
		        String infraRed = request.getParameter("infra_red");
		        String usb = request.getParameter("usb");
		        String camera = request.getParameter("camera");
		        String operatingSystemID = request.getParameter("operating_system");
		        String cpu = request.getParameter("cpu");
		        String sms = request.getParameter("sms");
		        String browser = request.getParameter("browser");
		        String java = request.getParameter("java");
		        String radio = request.getParameter("radio");
		        String music = request.getParameter("music");
		        String video = request.getParameter("video");
		        String office = request.getParameter("office");
		        String others = request.getParameter("others");
		        String standByTime = request.getParameter("stand_by_time");
		        String talkTime = request.getParameter("talk_time");
		        String state = "Còn hàng";
		        String catId = request.getParameter("catagory");
		        
		        
		        
		        sp.setHangSanXuat(new HangSanXuat(manufacturerID));
		        sp.setTenSP(name);
		        sp.setCamera(camera);
		        sp.setanhDaiDien(thumbnail);
		        sp.setBangTan(waveband);
		        sp.setBluetooth(bluetooth);
		        sp.setBoNhoTrong(internalMemory);
		        sp.setCheDoRung(shake);
		        sp.setCpu(cpu);
		        sp.setEdge(edge);
		        sp.setG3(_3g);
		        sp.setGiaBan(Integer.parseInt(price));
		        sp.setGiaSauKhiGiam(Integer.parseInt(discount));
		        sp.setGprs(gprs);
		        sp.setHeDieuHanh(new HeDieuHanh(operatingSystemID));
		        sp.setHinhAnh(image);
		        sp.setHongNgoai(infraRed);
		        sp.setJava(java);
		        sp.setKichThuoc(size);
		        sp.setKichThuocManHinh(resolution);
		        sp.setLoa(speaker);
		        sp.setMauSac(color);
		        
		        sp.setMusic(music);
		   //     sp.setNgayThang(ngayThang);
		        sp.setNgonNgu(language);
		        sp.setNhacChuong(ringTone);
		        sp.setOffice(office);
		        sp.setPhuKienDiKem(appendix);
		        sp.setRadio(radio);
		        sp.setSms(sms);
		        sp.setSoLuong(Integer.parseInt(quantity));
		        sp.setTheNhoNgoai(externalMemory);
		        sp.setThoiGianBaoHanh(warranty);
		        sp.setThoiGianCho(standByTime);
		        sp.setThoiGianThoai(talkTime);
		        sp.setThongTinManHinh(screenInfo);
		        sp.setThongTinNoiBat(salientFeature);
		        sp.setTinhNangKhac(others);
		        sp.setTrinhDuyet(browser);
		        sp.setTrangThai(state);
		        sp.setTrongLuong(weight);
		        sp.setUsb(usb);
		        sp.setVideo(video);
		        sp.setWifi(wlan);
		        int cat =Integer.parseInt(catId);
		        sp.updateMobile(sp, cat);
		        response.sendRedirect("ProductManage.jsp");
		        
		        
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	       
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
